﻿using Architecture.API.Application.TraceabilityCommand.SlaughterCommand;
using MediatR;
using Traceability.Domain.Service.SlaughterServices;
using Traceability.Domain.SlaughterDomain;

namespace Architecture.API.Application.TraceabilityCommandHandler.SlaughterCommandHandler
{
    /// <summary>
    /// 添加屠宰信息命令处理器
    /// </summary>
    public class AddSlaughterCommandHandler : IRequestHandler<AddSlaughterCommand, int>
    {
        /// <summary>
        /// 屠宰服务
        /// </summary>
        protected readonly ISlaughterService slaughterService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="slaughterService">屠宰服务</param>
        public AddSlaughterCommandHandler(ISlaughterService slaughterService)
        {
            this.slaughterService = slaughterService;
        }

        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(AddSlaughterCommand request, CancellationToken cancellationToken)
        {
            return await slaughterService.AddSlaughter(new Slaughter() {Batch=request.Batch,AveWeight=request.AveWeight,ArriveDate=request.ArriveDate,SlaughterTime=request.SlaughterTime, ShoppingId=request.ShoppingId,CreatedBy=request.CreatedBy,CreatedDate=DateTime.Now });
        }
    }
}
